﻿using Orchard.Mvc.Routes;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using Orchard.WebApi.Routes;
using System.Web.Http;

namespace NineSeas.Dashboard
{
    public class Routes : IRouteProvider, IHttpRouteProvider
    {

        IEnumerable<RouteDescriptor> IRouteProvider.GetRoutes()
        {
            return new[] {
                 new RouteDescriptor {
                    Priority = 11,
                    Route = new Route(
                        "Dashboard/{*data}",
                        new RouteValueDictionary {
                            {"area", "NineSeas.Dashboard"},
                            {"controller", "Home"},
                            {"action", "Index"}
                        },
                        new RouteValueDictionary(),
                        new RouteValueDictionary {
                            {"area", "NineSeas.Dashboard"}
                        },
                        new MvcRouteHandler())
                },
                
                 new RouteDescriptor {
                    Priority = 12,
                    Route = new Route(
                        "Dashboard/Localize/{action}",
                        new RouteValueDictionary {
                            {"area", "NineSeas.Dashboard"},
                            {"controller", "Localize"},
                            {"action", "Index"}
                        },
                        new RouteValueDictionary(),
                        new RouteValueDictionary {
                            {"area", "NineSeas.Dashboard"}
                        },
                        new MvcRouteHandler())
                }
                
            };
        }

        void IRouteProvider.GetRoutes(ICollection<RouteDescriptor> routes)
        {
            foreach (var routeDescriptor in ((IRouteProvider)this).GetRoutes())
                routes.Add(routeDescriptor);
        }

        IEnumerable<RouteDescriptor> IHttpRouteProvider.GetRoutes()
        {
            return new[] {
                new HttpRouteDescriptor {
                    Name = "ControllerOnlyGet",
                    Priority = 12,
                    RouteTemplate = "Dashboard/Services/{controller}",
                    Defaults = new { 
                        area = "NineSeas.Dashboard", 
                        controller = "Menu",
                        action = "Get"
                    },
                    Constraints = new { httpMethod = new HttpMethodConstraint("GET") }
                },
                new HttpRouteDescriptor {
                    Name = "ControllerOnlyPost",
                    Priority = 12,
                    RouteTemplate = "Dashboard/Services/{controller}",
                    Defaults = new { 
                        area = "NineSeas.Dashboard", 
                        controller = "Menu",
                        action = "Post"
                    },
                    Constraints = new { httpMethod = new HttpMethodConstraint("POST") }
                },
                new HttpRouteDescriptor {
                    Name = "ControllerAndActionAndId",
                    Priority = 12,
                    RouteTemplate = "Dashboard/Services/{controller}/{id}/{action}",
                    Defaults = new { 
                        area = "NineSeas.Dashboard",
                        action = "Get",
                        id = RouteParameter.Optional
                    },
                    Constraints = new {id = @"^\d{1,3}$"}
                },
                new HttpRouteDescriptor {
                    Name = "ControllerAndAction",
                    Priority = 12,
                    RouteTemplate = "Dashboard/Services/{controller}/{action}",
                    Defaults = new { 
                        area = "NineSeas.Dashboard",
                        action = "Get"
                    }
                }
            };
        }

        void IHttpRouteProvider.GetRoutes(ICollection<RouteDescriptor> routes)
        {
            foreach (var routeDescriptor in ((IHttpRouteProvider)this).GetRoutes())
                routes.Add(routeDescriptor);
        }
    }
}